import React from "react";
import axios from "axios";
import {Button, Form, Input} from "antd";

export default class UserRegister extends React.Component {
    constructor(props) {
        super(props);
        this.state = ({
            user:{}
        })
    }


    userRegister = () => {
        const url = 'http://localhost:8080/user/userRegister'
        const user = this.state.user;
        user.userName = document.getElementById('userName').value;
        user.userPassword = document.getElementById('userPassword').value;
        console.log(user)
        axios.post(url, user).then(
            (res) => {
                if (res.status == 200) {
                    alert("注册成功");
                    this.props.history.push({pathname: "/"});
                } else {
                    alert("注册失败，请重新注册")
                }
            }
        );
    }

    render() {
        return (
            <div className="UserRegister">
                <div className="RegisterBody">
                    <h1>用户注册</h1>
                    <Form
                        labelCol={{span: 24}}
                        wrapperCol={{span: 24}}
                    >

                        <Form.Item label="用户名：">
                            <Input
                                id="userName"
                                placeholder="请输入用户名"/>
                        </Form.Item>
                        <Form.Item label="密码：">
                            <Input.Password
                                placeholder="请输入密码"
                                id="userPassword"
                            />
                        </Form.Item>
                        <Form.Item>
                            <Button type="primary" onClick={this.userRegister}>注册</Button>
                        </Form.Item>
                    </Form>
                </div>
            </div>
        )
            ;
    }
}